package com.pactera.consts;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;

public class Const {

	public static String CONFIG_FILE = "config";
	//循环时间
	public static int TYPE1_QUART = 1;
	public static int EVERYDAY = 24*60*60*1000;
	public static int TYPE3_QUART = 1;
	public static int TYPE4_QUART = 1;
	public static int TYPE6_QUART = 1;

	// ORACLE数据库信息
	public static String ORACLE_URL;
	public static String ORACLE_USER;
	public static String ORACLE_PASSWD;
	// POSTGRES数据库信息
	public static String POSTGRES_URL;
	public static String POSTGRES_USER;
	public static String POSTGRES_PASSWD;
	//短信信息
	public static String SMS_WSDL;
	public static String SMS_SP_CODE;
	public static String SMS_USER;
	public static String SMS_PWD;
	public static String SMS_SI;
	public static int SMS_ELIPSIS_SIZE;
	//短信类型
	//普通错误类型，定时循环监测所有错误作业
	public static String SMS_TYPE_1="1";
	//特定时间监测特定作业状态
	public static String SMS_TYPE_2="2";
	//3
	public static String SMS_TYPE_3="3";
	//间隔时间判断一次,组是否完成
	public static String SMS_TYPE_4="4";
	//间隔多长时间判断一次,作业是否都完成
	public static String SMS_TYPE_6="6";

	//短信发送状态，1成功，0失败, 体现在sms_log.state字段
	public static int SMS_SEND_SUCCESS=1;
	public static int SMS_SEND_FAILED=0;
	
	public static void initConfig() {
		
			try {
				System.out.println("开始获取外部配置文件");
				Properties properties = new Properties();
	        	File file = new File(CONFIG_FILE+".properties");
	        	FileInputStream fis = new FileInputStream(file);
	        	properties.load(fis);
	        	fis.close();
	        	ORACLE_URL = properties.getProperty("ORACLE_URL");
	    		ORACLE_USER = properties.getProperty("ORACLE_USER");
	    		ORACLE_PASSWD = properties.getProperty("ORACLE_PASSWD");
	    		POSTGRES_URL = properties.getProperty("POSTGRES_URL");
	    		POSTGRES_USER = properties.getProperty("POSTGRES_USER");
	    		POSTGRES_PASSWD = properties.getProperty("POSTGRES_PASSWD");
	    		SMS_WSDL = properties.getProperty("SMS_WSDL");
	    		SMS_SP_CODE = properties.getProperty("SMS_SP_CODE");
	    		SMS_USER = properties.getProperty("SMS_USER");
	    		SMS_PWD = properties.getProperty("SMS_PWD");
	    		SMS_SI = properties.getProperty("SMS_SI");
				SMS_ELIPSIS_SIZE=Integer.valueOf(properties.getProperty("SMS_ELIPSIS_SIZE"));
	    	
	    		String TYPE1[] = properties.getProperty("TYPE1_QUART").split("\\*");
	    		for (int i = 0; i < TYPE1.length; i++) {
	    			TYPE1_QUART = TYPE1_QUART * Integer.valueOf(TYPE1[i]);
	    		}
	    		String TYPE3[] = properties.getProperty("TYPE3_QUART").split("\\*");
	    		for (int i = 0; i < TYPE3.length; i++) {
	    			TYPE3_QUART = TYPE3_QUART * Integer.valueOf(TYPE3[i]);
	    		}
				String TYPE4[] = properties.getProperty("TYPE4_QUART").split("\\*");
				for (int i = 0; i < TYPE4.length; i++) {
					TYPE4_QUART = TYPE4_QUART * Integer.valueOf(TYPE4[i]);
				}
				String TYPE6[] = properties.getProperty("TYPE6_QUART").split("\\*");
				for (int i = 0; i < TYPE6.length; i++) {
					TYPE6_QUART = TYPE6_QUART * Integer.valueOf(TYPE6[i]);
				}
			} catch (FileNotFoundException e1) {
				// TODO Auto-generated catch block
				System.out.println("外部没有配置文件，获取内部文件");
				try {
					ResourceBundle p = ResourceBundle.getBundle(CONFIG_FILE);
					ORACLE_URL = p.getString("ORACLE_URL");
					ORACLE_USER = p.getString("ORACLE_USER");
					ORACLE_PASSWD = p.getString("ORACLE_PASSWD");
					POSTGRES_URL = p.getString("POSTGRES_URL");
					POSTGRES_USER = p.getString("POSTGRES_USER");
					POSTGRES_PASSWD = p.getString("POSTGRES_PASSWD");
					SMS_WSDL = p.getString("SMS_WSDL");
					SMS_SP_CODE = p.getString("SMS_SP_CODE");
					SMS_USER = p.getString("SMS_USER");
					SMS_PWD = p.getString("SMS_PWD");
					SMS_SI = p.getString("SMS_SI");
					SMS_ELIPSIS_SIZE=Integer.valueOf(p.getString("SMS_ELIPSIS_SIZE"));
				
					String TYPE1[] = p.getString("TYPE1_QUART").split("\\*");
					for (int i = 0; i < TYPE1.length; i++) {
						TYPE1_QUART = TYPE1_QUART * Integer.valueOf(TYPE1[i]);
					}
					String TYPE3[] = p.getString("TYPE3_QUART").split("\\*");
					for (int i = 0; i < TYPE3.length; i++) {
						TYPE3_QUART = TYPE3_QUART * Integer.valueOf(TYPE3[i]);
					}
					String TYPE4[] = p.getString("TYPE4_QUART").split("\\*");
					for (int i = 0; i < TYPE4.length; i++) {
						TYPE4_QUART = TYPE4_QUART * Integer.valueOf(TYPE4[i]);
					}
					String TYPE6[] = p.getString("TYPE6_QUART").split("\\*");
					for (int i = 0; i < TYPE6.length; i++) {
						TYPE6_QUART = TYPE6_QUART * Integer.valueOf(TYPE6[i]);
					}
				}catch (MissingResourceException e) {
					System.out.println("程序内部没有配置文件");
				}
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				System.out.println("io异常");
				e1.printStackTrace();
			}
		
        }
	
}
